package com.qf.sclg.controller;

import com.qf.sclg.entity.Subject;
import com.qf.sclg.result.ResponseData;
import com.qf.sclg.service.SubjectService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * (Subject)表控制层
 *
 * @author makejava
 * @since 2021-10-13 14:23:35
 */
//结果封装成jsion格式
@RestController
@RequestMapping("subject")
public class SubjectController {
   @Autowired
   private SubjectService subjectService;
   @ApiOperation(value = "通过项目类型查找")
   @ApiImplicitParam(name = "type",value = "项目类型",dataType = "string")
   @GetMapping("/query/{type}")
   public ResponseData queryByCondition(@PathVariable String type){
      List<Subject> subjects= subjectService.queryByType(type);
      if (subjects.size() == 0){
         return new ResponseData("1002","无数据");
      }
      return  new ResponseData(subjects);
   }
   @ApiOperation(value = "通过项目id查找信息")
   @ApiImplicitParam(name = "id",value = "项目id",dataType = "int",required = true)
//   @GetMapping("/query/{id}")默认与上述相同地址
   @GetMapping("/query/one/{id}")
   public ResponseData queryById(@PathVariable Integer id){
      Subject subject = subjectService.queryById(id);
      if(subject == null){
         return  new ResponseData("1002","无数据");
      }
      return new ResponseData(subject);

   }

   @ApiOperation(value = "查找所有的项目名称")
   @GetMapping("/suname")
   public ResponseData querySuName() {
      List<String> sunames= subjectService.querySuName();
      return new ResponseData(sunames);
   }
}

